#ifndef SKYVIEW_H
#define SKYVIEW_H

#include <QDeclarativeItem>

class SkyViewPrivate;

class SkyView : public QDeclarativeItem
{
    Q_OBJECT
    Q_PROPERTY(qreal azimuth READ azimuth WRITE setAzimuth NOTIFY azimuthChanged)
    Q_PROPERTY(qreal altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged)
    Q_PROPERTY(qreal fov READ fov WRITE setFov NOTIFY fovChanged)
    Q_PROPERTY(qreal viewportWidthHours READ viewportWidthHours NOTIFY viewportWidthHoursChanged)
    Q_PROPERTY(qreal viewportHeightDegrees READ viewportHeightDegrees NOTIFY viewportHeightDegreesChanged)
public:
    explicit SkyView(QDeclarativeItem *parent = 0);
    virtual ~SkyView();

    /** @overload QDeclarativeItem::paint()
      */
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);

    /** Get current view azimuth.
      * @return azimuth in hours.
      */
    qreal azimuth() const;

    /** Get current view altitude.
      * @return altitude in degrees.
      */
    qreal altitude() const;

    /** Get current field of view setting.
      * @return field of view in radians.
      */
    qreal fov() const;

    /** Get current viewport width in decimal hours.
      * @return viewport width in decimal hours.
      */
    qreal viewportWidthHours() const;

    /** Get current vieport height in decimal degrees.
      * @return viewport height in decimal degrees.
      */
    qreal viewportHeightDegrees() const;

signals:
    /** Emitted when view azimuth changes.
      */
    void azimuthChanged();

    /** Emitted when view altitude changes.
      */
    void altitudeChanged();

    /** Emitted when field of view changes.
      */
    void fovChanged();

    /** Emitted when field of view changes.
      */
    void viewportWidthHoursChanged();

    /** Emitted when field of view changes.
      */
    void viewportHeightDegreesChanged();

public slots:
    /** Set new view azimuth.
      * @param azimuth new azimuth in hours.
      */
    void setAzimuth(qreal azimuth);

    /** Set new view altitude.
      * @param altitude new altitude in degrees.
      */
    void setAltitude(qreal altitude);

    /** Set new field of view.
      * @param fov new field of view in radians.
      */
    void setFov(qreal fov);

private:
    friend class SkyViewPrivate;
    SkyViewPrivate* const d;

    /** Paint sky view background
      * @param painter painter as passed to paint().
      */
    void paintGrid(QPainter* painter) const;

    /** Paint sky objects
      * @param painter painter as passed to paint().
      */
    void paintObjects(QPainter* painter) const;

    /** Map given RA and DEC to screen coordinates.
      * @param ra the right ascension in radians.
      * @param dec the declination in radians.
      * @return a point in screen coordinates.
      */
    QPoint mapToScreenPoint(qreal ra, qreal dec) const;

    /** Get azimuth of left edge of viewport in hours.
      * @return azimuth of left edge of viewport in hours.
      */
    qreal leftEdgeAzimuth() const;
};

#endif // SKYVIEW_H
